package mebp;

import java.util.Vector;

import mebp.genetic.Individuum;
import mebp.genetic.Population;

/** Minimum Energy Broadcast Problem **/

public class MEBP extends Vector<Node> {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -6189961047399495377L;
	public transient DistanceSortedNodes sortedDistances;
	public final static double powerExponent=3;
	
	public static double radiusToPower(double radius) {
		return Math.pow(radius, powerExponent);
	}
	
	final static double lpe=Math.log(powerExponent);
	public static double powerToRadius(double power) {
		return Math.log(power)/lpe;
	}
	
	
	public double neighbourCountToPower(int from, int neighbourCount) {
		
		return radiusToPower(sortedDistances.getNodeNeighbourDistance(from, neighbourCount));
		
	}
	
	/**
	 * Generate Empty ProblemSetting
	 */
	public MEBP () {
		super();
	}
	
	/**
	 * Generate ProblemSetting of a specific size
	 * @param size
	 */
	public MEBP(int size) {
		super(size);
	}
	
	
	/**
	 * Problemsetting from NodeSet
	 * incl. update();
	 * @param nodes
	 */
	public MEBP(Vector<Node> nodes) {
		super(nodes.size());
		for (Node n:nodes) this.add(n);
		update();
	}
	
	/**
	 * Problemsetting from Node-Array
	 * incl. update();
	 * @param nodes
	 */
	public MEBP(Node[] nodes) {
		super(nodes.length);
		for (Node n:nodes) this.add(n);
		update();
	}
	
	
	/**
	 * Get Number of Nodes
	 * @return
	 */
	public int getProblemSize() {
		return this.size();
	}
	
	
	/**
	 * Update internal Tables, after changing Nodes
	 */
	public void update() {
		sortedDistances=new DistanceSortedNodes(this);
	}
	
	
	/**
	 * Generate a starting Population
	 * @param size
	 * @return
	 */
	public Population generateStartPopulation(int size) {
		Population ret=new Population();
		update();
		for (int i=0;i<size;i++) {
			ret.add(new Individuum(this));
		}
		return ret;
	}
	
	
}
